package com.doubi.controller.sysPermission;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.doubi.common.config.shiro.ShiroUtil;
import com.doubi.model.sys.TSysRole;
import com.doubi.service.SysRoleService;
import com.doubi.utils.DataUtil;
import com.doubi.vo.AppModel;
import com.doubi.vo.PageVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by IntelliJ IDEA.
 * User: MrDoubi
 * Date: 2019/6/27
 * Time: 10:08
 */
@Controller
@RequestMapping("sysRole")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;



    /**
     * MrDoubi
     * 2019年1月10日 15:04:57
     * 角色权限编辑
     * @return 页面
     */
    @RequiresPermissions("sysRole:list")
    @GetMapping("list")
    public String list(){
        return "web/sysRole/list";
    }


    /**
     * MrDoubi
     * 2019年1月10日 15:05:23
     * 权限列表json
     * @return model
     */
    @RequiresPermissions("sysRole:listPage")
    @PostMapping("listPage")
    @ResponseBody
    public PageVo<TSysRole> getList(PageVo<TSysRole> page, TSysRole sysRole){
        return sysRoleService.getPage(page,sysRole);
    }


    /**
     * 功能说明：角色修改页面
     * @author  MrDoubi 2019-01-10 15:19:45
     * @param sysRole bean
     * @param model model
     * @return 页面
     */
    @RequiresPermissions("sysRole:edit")
    @GetMapping("edit")
    public String edit(TSysRole sysRole, Model model){
        if(DataUtil.isNotEmpty(sysRole) && DataUtil.isNotEmpty(sysRole.getOid())){
            sysRole = sysRoleService.getById(sysRole.getOid());
        }
        model.addAttribute("bean",sysRole);
        return "web/sysRole/edit";
    }


    /**
     * 功能说明：角色添加或者修改
     * @author  MrDoubi 2019-01-10 15:20:41
     * @param sysRole bean
     * @return model
     */
    @RequiresPermissions("sysRole:saveOrUpdate")
    @PostMapping("saveOrUpdate")
    @ResponseBody
    public AppModel saveOrUpdate(TSysRole sysRole){
        return sysRoleService.saveBean(sysRole, ShiroUtil.getUser());
    }


    /**
     * 功能说明：删除角色
     * @author  MrDoubi 2019-01-10 15:21:08
     * @param sysRole bean
     * @return model
     */
    @RequiresPermissions("sysRole:delBean")
    @PostMapping("delBean")
    @ResponseBody
    public AppModel delBean(TSysRole sysRole){
        return sysRoleService.delBean(sysRole);
    }
}
